
using System.Collections.Generic;
using UnityEngine;

public class EventMgr
{
    private static EventMgr _ins;
    public static EventMgr Ins
    {
        get
        {
            if (_ins == null)
            {
                _ins = new EventMgr();
            }
            return _ins;
        }
    }

    public delegate void EventHandle(object param = null);

    private Dictionary<string, List<EventHandle>> eventDic = new Dictionary<string, List<EventHandle>>();


    public void AttachEvent(string Msg, EventHandle eventHandle)
    {
        if (!eventDic.ContainsKey(Msg))
        {
            eventDic.Add(Msg, new List<EventHandle>());
        }

        eventDic[Msg].Add(eventHandle);
    }

    public void TriggerEvent(string Msg, object param = null)
    {
        if (eventDic.ContainsKey(Msg))
        {
            foreach (EventHandle handle in eventDic[Msg])
            {
                handle(param);
            }
        }
        else
        {
            Debug.LogError(Msg + " is undefine from function: _EventBaseManager::_TriigerEvent");
        }
    }

}